package com.awt.action;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/**
 * @authoer zsj
 * @date 2023/4/17 10:10
 */
public class ActionDemo2 {


    public static void main(String[] args) {
        Frame frame = new Frame();
        Choice choice = new Choice();
        TextField textField = new TextField();
        Box box = Box.createHorizontalBox();
        choice.add("aaa");
        choice.add("bbb");
        choice.add("ccc");
        box.add(textField);
        box.add(choice);

        textField.addTextListener(new TextListener() {
            @Override
            public void textValueChanged(TextEvent e) {
                System.out.println(e.paramString());
            }
        });

        choice.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                System.out.println("当前选中为" + e.getItem());
            }
        });

        frame.addContainerListener(new ContainerAdapter() {
            @Override
            public void componentAdded(ContainerEvent e) {
                Component child = e.getChild();
                System.out.println(child);
            }

            @Override
            public void componentRemoved(ContainerEvent e) {

            }
        });



        frame.add(box);
        frame.pack();
        frame.setVisible(true);

    }
}
